home *** CD-ROM | disk | FTP | other *** search
/ Download Now 8 / Download Now V8.iso / Program / InternetTools / ApacheWebServer1.3.6 / apache_1_3_6_win32.exe / _SETUP.1 / apachectl < prev    next >
Encoding:
Text File  |  1999-02-09  |  7.1 KB  |  230 lines

  1. #!/bin/sh
  2. #
  3. # Apache control script designed to allow an easy command line interface
  4. # to controlling Apache.  Written by Marc Slemko, 1997/08/23
  5. # The exit codes returned are:
  6. #    0 - operation completed successfully
  7. #    1 - 
  8. #    2 - usage error
  9. #    3 - httpd could not be started
  10. #    4 - httpd could not be stopped
  11. #    5 - httpd could not be started during a restart
  12. #    6 - httpd could not be restarted during a restart
  13. #    7 - httpd could not be restarted during a graceful restart
  14. #    8 - configuration syntax error
  15. #
  16. # When multiple arguments are given, only the error from the _last_
  17. # one is reported.  Run "apachectl help" for usage info
  18. #
  19. #
  20. # |||||||||||||||||||| START CONFIGURATION SECTION  ||||||||||||||||||||
  21. # --------------------                              --------------------
  22. # the path to your PID file
  23. PIDFILE=/usr/local/apache/logs/httpd.pid
  24. #
  25. # the path to your httpd binary, including options if necessary
  26. HTTPD='/usr/local/apache/src/httpd'
  27. #
  28. # a command that outputs a formatted text version of the HTML at the
  29. # url given on the command line.  Designed for lynx, however other
  30. # programs may work.  
  31. LYNX="lynx -dump"
  32. #
  33. # the URL to your server's mod_status status page.  If you do not
  34. # have one, then status and fullstatus will not work.
  35. STATUSURL="http://localhost/server-status"
  36. #
  37. # --------------------                              --------------------
  38. # ||||||||||||||||||||   END CONFIGURATION SECTION  ||||||||||||||||||||
  39.  
  40. ERROR=0
  41. ARGV="$@"
  42. if [ "x$ARGV" = "x" ] ; then 
  43.     ARGS="help"
  44. fi
  45.  
  46. for ARG in $@ $ARGS
  47. do
  48.     # check for pidfile
  49.     if [ -f $PIDFILE ] ; then
  50.     PID=`cat $PIDFILE`
  51.     if [ ! "x$PID" = "x" ] && kill -0 $PID; then
  52.         STATUS="httpd (pid $PID) running"
  53.         RUNNING=1
  54.     else
  55.         STATUS="httpd (pid $PID?) not running"
  56.         RUNNING=0
  57.     fi
  58.     else
  59.     STATUS="httpd (no pid file) not running"
  60.     RUNNING=0
  61.     fi
  62.  
  63.     case $ARG in
  64.     start)
  65.     if [ $RUNNING -eq 1 ]; then
  66.         echo "$0 $ARG: httpd (pid $PID) already running"
  67.         continue
  68.     fi
  69.     if $HTTPD ; then
  70.         echo "$0 $ARG: httpd started"
  71.     else
  72.         echo "$0 $ARG: httpd could not be started"
  73.         ERROR=3
  74.     fi
  75.     ;;
  76.     stop)
  77.     if [ $RUNNING -eq 0 ]; then
  78.         echo "$0 $ARG: $STATUS"
  79.         continue
  80.     fi
  81.     if kill $PID ; then
  82.         echo "$0 $ARG: httpd stopped"
  83.     else
  84.         echo "$0 $ARG: httpd could not be stopped"
  85.         ERROR=4
  86.     fi
  87.     ;;
  88.     restart)
  89.     if [ $RUNNING -eq 0 ]; then
  90.         echo "$0 $ARG: httpd not running, trying to start"
  91.         if $HTTPD ; then
  92.         echo "$0 $ARG: httpd started"
  93.         else
  94.         echo "$0 $ARG: httpd could not be started"
  95.         ERROR=5
  96.         fi
  97.     else
  98.         if $HTTPD -t >/dev/null 2>&1; then
  99.         if kill -HUP $PID ; then
  100.             echo "$0 $ARG: httpd restarted"
  101.         else
  102.             echo "$0 $ARG: httpd could not be restarted"
  103.             ERROR=6
  104.         fi
  105.         else
  106.         echo "$0 $ARG: configuration broken, ignoring restart"
  107.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  108.         ERROR=6
  109.         fi
  110.     fi
  111.     ;;
  112.     graceful)
  113.     if [ $RUNNING -eq 0 ]; then
  114.         echo "$0 $ARG: httpd not running, trying to start"
  115.         if $HTTPD ; then
  116.         echo "$0 $ARG: httpd started"
  117.         else
  118.         echo "$0 $ARG: httpd could not be started"
  119.         ERROR=5
  120.         fi
  121.     else
  122.         if $HTTPD -t >/dev/null 2>&1; then
  123.         if kill -USR1 $PID ; then
  124.             echo "$0 $ARG: httpd gracefully restarted"
  125.         else
  126.             echo "$0 $ARG: httpd could not be restarted"
  127.             ERROR=7
  128.         fi
  129.         else
  130.         echo "$0 $ARG: configuration broken, ignoring restart"
  131.         echo "$0 $ARG: (run 'apachectl configtest' for details)"
  132.         ERROR=7
  133.         fi
  134.     fi
  135.     ;;
  136.     status)
  137.     $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
  138.     ;;
  139.     fullstatus)
  140.     $LYNX $STATUSURL
  141.     ;;
  142.     configtest)
  143.     if $HTTPD -t; then
  144.         :
  145.     else
  146.         ERROR=8
  147.     fi
  148.     ;;
  149.     *)
  150.     echo "usage: $0 (start|stop|restart|fullstatus|status|graceful|configtest|help)"
  151.     cat <<EOF
  152.  
  153. start      - start httpd
  154. stop       - stop httpd
  155. restart    - restart httpd if running by sending a SIGHUP or start if 
  156.              not running
  157. fullstatus - dump a full status screen; requires lynx and mod_status enabled
  158. status     - dump a short status screen; requires lynx and mod_status enabled
  159. graceful   - do a graceful restart by sending a SIGUSR1 or start if not running
  160. configtest - do a configuration syntax test
  161. help       - this screen
  162.  
  163. EOF
  164.     ERROR=2
  165.     ;;
  166.  
  167.     esac
  168.  
  169. done
  170.  
  171. exit $ERROR
  172.  
  173. # ====================================================================
  174. # Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
  175. # Redistribution and use in source and binary forms, with or without
  176. # modification, are permitted provided that the following conditions
  177. # are met:
  178. # 1. Redistributions of source code must retain the above copyright
  179. #    notice, this list of conditions and the following disclaimer. 
  180. # 2. Redistributions in binary form must reproduce the above copyright
  181. #    notice, this list of conditions and the following disclaimer in
  182. #    the documentation and/or other materials provided with the
  183. #    distribution.
  184. # 3. All advertising materials mentioning features or use of this
  185. #    software must display the following acknowledgment:
  186. #    "This product includes software developed by the Apache Group
  187. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  188. # 4. The names "Apache Server" and "Apache Group" must not be used to
  189. #    endorse or promote products derived from this software without
  190. #    prior written permission. For written permission, please contact
  191. #    apache@apache.org.
  192. # 5. Products derived from this software may not be called "Apache"
  193. #    nor may "Apache" appear in their names without prior written
  194. #    permission of the Apache Group.
  195. #
  196. # 6. Redistributions of any form whatsoever must retain the following
  197. #    acknowledgment:
  198. #    "This product includes software developed by the Apache Group
  199. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  200. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  201. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  202. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  203. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  204. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  205. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  206. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  207. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  208. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  209. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  210. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  211. # OF THE POSSIBILITY OF SUCH DAMAGE.
  212. # ====================================================================
  213. # This software consists of voluntary contributions made by many
  214. # individuals on behalf of the Apache Group and was originally based
  215. # on public domain software written at the National Center for
  216. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  217. # For more information on the Apache Group and the Apache HTTP server
  218. # project, please see <http://www.apache.org/>.
  219.